const db = wx.cloud.database();
const app = getApp();
Page({
  data: {
    id: app.globalData.userInfo._id,
    name: app.globalData.userInfo.nickName,
    password: ''
  },
  onLoad: function (options) {},
  // onChangeNickName: function (e) {
  //   this.setData({
  //     name: e.detail
  //   })
  // },
  onChangePassWord: function (e) {
    this.setData({
      password: e.detail
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },
  onSubmit: function () {
    // console.log(this.data.name,this.data.password)
    // console.log(this.data.id)
    if (this.data.password) {
      db.collection('Management_user').doc(this.data.id).update({
        data: {
          passWord: this.data.password
        },
        success: function (res) {
          console.log(res)
          if (res.stats.updated === 1) {
            wx.showToast({
              title: '修改成功',
              icon: 'success'
            })
            wx.navigateBack({
              delta: 0,
            })
          } else {
            wx.showToast({
              title: '修改失败',
              icon: 'error'
            })
          }
        }
      })
    }
  }
})